package com.lc.afbx.conn;

import android.renderscript.Type;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.AsyType;
import com.zcx.helper.http.note.HttpCache;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/26.
 */
@HttpInlet(Conn.INLET_API_INDEX_INDEX)
public class GetApiIndexIndex extends BaseAsyGet<GetApiIndexIndex.Info> {

    public GetApiIndexIndex(AsyCallBack asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            Info info = new Info();

            JSONArray array = object.optJSONArray("data");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject o = array.optJSONObject(i);

                    Data data = new Data();

                    data.id = o.optString("id");

                    data.picurl = Conn.PIC + o.optString("picurl");

                    info.datas.add(data);

                }

            }

            array = object.optJSONArray("news");

            if (array != null) {

                for (int i = 0; i < array.length(); i++) {

                    JSONObject o = array.optJSONObject(i);

                    New aNew = new New();

                    aNew.id = o.optString("id");

                    aNew.picurl = Conn.PIC + o.optString("picurl");

                    aNew.title = o.optString("title");

                    aNew.posttime = o.optString("posttime");

                    info.news.add(aNew);

                }

            }

            return info;

        }

        return null;

    }

    public static class Info {

        public List<Data> datas = new ArrayList<>();

        public List<New> news = new ArrayList<>();

    }

    public static class Data {

        public String id, picurl;

    }

    public static class New {

        public String id, title, picurl, posttime;

    }

}
